package com.example.wangfanwangluo.wangfanboss;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.view.WindowManager;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.example.wangfanwangluo.wangfanboss.PublicDirectory.functions;

public class Login extends AppCompatActivity {
    private EditText phone_num;
    private EditText password;
    private TextView login_tv;
    private TextView forget_tv;
    private TextView username_tv;
    private TextView jihuo_btn;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
        //隐藏状态栏
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
     //隐藏系统自带标题栏
        ActionBar actionbar = getSupportActionBar();
        if (actionbar != null){
            actionbar.hide();
        }
        initViews();
    }

    //初始化view
    private void initViews(){
        phone_num = (EditText)findViewById(R.id.phone_num);
        password = (EditText)findViewById(R.id.password);
        login_tv = (TextView)findViewById(R.id.login_btn);
        forget_tv = (TextView)findViewById(R.id.forget);
        username_tv = (TextView)findViewById(R.id.username);
        jihuo_btn = (TextView)findViewById(R.id.jihuo_btn);

        //添加监听事件
        login_tv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //点击登录，校验手机号是否合法，密码是否符合规则
               //获取手机号 密码 的内容,进行校验
                String phonestr = phone_num.getText().toString();
                String pwstr = password.getText().toString();
                if (!functions.phoneCheck(phonestr)){
                    Toast.makeText(Login.this,"请填写正确手机号", Toast.LENGTH_SHORT).show();
                    return;
                }
                if (!functions.pwCheck(pwstr)){
                    Toast.makeText(Login.this,"密码位数有误",Toast.LENGTH_SHORT).show();
                    return;
                }
                //网络请求，存储信息
                //进入主页
                Intent intent = new Intent(Login.this,MainActivity.class);
                startActivity(intent);
                finish(); // 登录界面消失
            }
        });
        forget_tv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //进入忘记密码页面
                Intent intent = new Intent(Login.this,forget1.class);
                startActivity(intent);
                Log.d("login","进入忘记密码1");
            }
        });
        jihuo_btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //激活落货方界面
                Intent intent = new Intent(Login.this,register.class);
                startActivity(intent);
            }
        });
//        register_tv.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
                //进入注册页面
//                Intent intent = new Intent(Login.this,register.class);
//                startActivity(intent);
//            }
//        });
    }

}
